import { request } from './reuqest.js';
import uploadImage from '@/utils/ossutil/uploadFile.js';
/**
 * 微信登录
 * code: 微信 uni.login => code
 */
const login = async (data) => {
	let result = await uni.login();
	let { code } = result;
	return request({
		url: 'User/WxLogin',
		data: {
			code
		},
		method: 'POST'
	})
};

/**
 * 同步用户信息
 * userName
 * gender
 * imgUrl
 * city
 * province
 * country
 */
const syncWxUserInfo = (data) => {
	return request({
		url: 'User/SyncWxUserInfo',
		data,
		method: 'POST'
	})
};

/**
 * 上传图片(oss)
 * path 图片文件
 */
const uploadImages = (path) => {
	return new Promise((resolve, reject) => {
		uploadImage(path, 'images/', result => {
			resolve(JSON.stringify(result))
		}, error => {
			reject(error)
		})
	})
}

export {
	login,
	syncWxUserInfo,
	uploadImages
}